How to integrate Client folders with DOORS folders question

I wish to be able to create a DXL script to restore archived files.

I want to be able to select a default directory to restore to, using the current folder in by selecting a folder in DOORS database.
I have archived modules on my laptop, which I wish to be able to restore via a script to a select folder(selected above).

I wish to be able to read in the source directory, go through each item in the folder, and then restoring each item in the destination folder.

Anyone have any suggestions on how to modify my existing code for this, if it even possible?

Thank you

Here is my current script:

/*
 Rev 1.000 - This script will perform an archive restore on modules residing in the DOORS Development server area.
 Input - N/A
 Output - N/A
*/
string strModuleName
string strNewLine = "\n"
//Draws a bitmap - for canvases that displays an image
void repaint(DBE graph) {
    background(graph,
        logicalMediumIndicatorColor)
    // draw picture here
} // repaint 
 
void RestoreModule(string strFullName)
{
        bool bValidModule = true
        bool bRestoreStatus
        string message = restoreModule strFullName 
        if (!null message) 
        {
                ack message
                //halt
        } 
        print "Module " strFullName strNewLine
}  // RestoreModule()
 
void ProcessFolder(Folder fld)
{       
        Item itm
        string FullModuleName
        string ModuleName
 
        Skip skpItems = createString()  // used to put items alphabetically sorted
                  // [1] Get items in the folder
        for itm in fld do
        {
                if (!isDeleted(itm)) put(skpItems, name(itm), itm)
        }// for itm in fld do
                 // [2] process modules in the folder
        for itm in skpItems do
        {
                if (type(itm) == "Formal")
                {
                        FullModuleName = fullName(itm)
                        ModuleName = name(itm)
                        RestoreModule(ModuleName)
                } // end if (type(itm) == "Formal")
        } // end for itm in skpItems do
                // [3] recurse sub-folders and projects
        for itm in skpItems do
        {
                if (type(itm) == "Folder" or type(itm) == "Project")
                        ProcessFolder(folder(fullName(itm)))
        } // end for itm in skpItems do
        delete(skpItems)
} // ProcessFolder
string strDestinationFolderName = "/Test Area/ICAR/TOOLS Test Area/Test"// Doors directory
string strSourceFolderName = "U:\\DXL\\DMA"     // Laptop
string strDialogTitle = "Restore Modules "
string strDefaultFolderPath = fullName current Folder
DB RestoreModuleBox = create(strDialogTitle)
imageCanvas = canvas(RestoreModuleBox, 400, 95, repaint)               //puts the GE logo at top
DBE dbeLabel = label(RestoreModuleBox, "User shall be able to run a script on a directory to Restore module(s).")
DBE dbeDefaultFolderPath = field(RestoreModuleBox, "Folder Path:","", 80,true)   //Setting to true grays out this field
// use this code from SmartDxl.com
//DBE dbeDestFolder = directoryName(RestoreModuleBox, "Destination Folder: ", strDestinationFolderName, false)
 
void Insert(DB RestoreModuleBox)
{
        string strFilename
        string strSourceDirectory = strSourceFolderName  // hard coded for test
        //string strDestDirectory = get dbeDestFolder 
        pragma runLim, 0                                           //disables the "Execution Timeout" dialog
        if (strSourceDirectory != null)
        {
bool bStatus = folder(strSourceFolderName)
print "bStatus " bStatus " " strSourceFolderName strNewLine
// bStatus is false
//ProcessFolder(current folder strDestinationFolderName)
//Unsuccessful at passing in the laptop directory to this function
          //      infoBox "Modules Restored from " strSourceDirectory " to " strDestDirectory
        } // end if (strSourceDirectory != null)
        if (showing RestoreModuleBox)
        {
                hide(RestoreModuleBox)
                destroy(RestoreModuleBox)  // free up resources now
        } // end if (showing RestoreModuleBox)
} // Insert
apply(RestoreModuleBox, "OK", Insert)
set(dbeDefaultFolderPath, strDefaultFolderPath) // Update into the folder path area in dialog
show RestoreModuleBox  // No text can appear after here as it will not be executed!!!!!!!!!

Gedinfo - Wed Apr 25 15:40:04 EDT 2012

Re: How to integrate Client folders with DOORS folders question
llandale - Wed Apr 25 16:28:20 EDT 2012

Here's a snippette to find all the files in a particular Windows directory:

for NameFile in directory NameDir do
{  if (NameFile[0:0] == ".")    // skip the "." and ".." file names.  No other name may begin with '.'
      continue
   if (NameFile == NameDir)     // Don't recall why, but skip a file with exact name as Directory
   {  print  ">>SearchDir, NameFile == NameDir '" NameFile "'\n"
      continue
   }
   NameFull     = NameDir "\\" NameFile
   stat = create(NameFull)
//    print "considering >" NameFull "<\n"
   if (null stat) //
   then something is wrong
   else
   {  if (directory(stat)) //
      then this is a sub-folder
      else this is a file
      delete(stat)
   }
}


-Louie

Re: How to integrate Client folders with DOORS folders question
Gedinfo - Thu Apr 26 12:39:39 EDT 2012

Thanks for the response Louie.

I adapted your code, but now get a fail on restore. I have a directory of archived modules(*.dma), and for each module, restoreModule returns "Archive file does not exist".

Yet, if I go through File > Restore > Module, the archived file is restored.

Re: How to integrate Client folders with DOORS folders question
llandale - Thu Apr 26 13:55:57 EDT 2012

Gedinfo - Thu Apr 26 12:39:39 EDT 2012
Thanks for the response Louie.

I adapted your code, but now get a fail on restore. I have a directory of archived modules(*.dma), and for each module, restoreModule returns "Archive file does not exist".

Yet, if I go through File > Restore > Module, the archived file is restored.

Print the file name before you try to restore it.
I think you messed up the file name, such as failing to insert a slash between the path and the basename.
  • FullPath = Directory "\\" NameFile

-Louie

Re: How to integrate Client folders with DOORS folders question
Gedinfo - Thu Apr 26 15:31:39 EDT 2012

In my updated code, I get a message that the "New module name is invalid".

My code appears below:
 

/*
 Rev 1.000 - This script will perform an archive restore on modules residing in the DOORS Development server area.
 Input - N/A
 Output - N/A
*/
string strModuleName
string strNewLine = "\n"
//Draws a bitmap - for canvases that displays an image
void repaint(DBE graph) {
    background(graph,
        logicalMediumIndicatorColor)
    // draw picture here
} // repaint 
 
string strDestinationFolderName = "/Test Area/ICAR/TOOLS Test Area/Test"// Doors directory
string strSourceFolderName = "U:\\DXL\\DMA"     // Laptop
string strDialogTitle = "Restore Modules "
string strDefaultFolderPath = fullName current Folder
DB RestoreDialog = create(strDialogTitle)
imageCanvas = canvas(RestoreDialog, 400, 95, repaint)               //puts the GE logo at top
DBE dbeLabel = label(RestoreDialog, "User shall be able to run a script on a directory to Restore module(s).")
DBE dbeDefaultFolderPath = field(RestoreDialog, "Folder Path:","", 80,true)   //Setting to true grays out this field

/******************************************************************************
  fReplaceUnderscore
  
  Replaces underscores in a buffer with spaces
******************************************************************************/
void fReplaceUnderscore(Buffer in_buf)
{       // Replace all occurances of underscore to space in the Buffer
        char in_cFrom = '_'
        char in_cTo = ' '
        if (null in_buf) return
        int i
        for (i=0; i<length(in_buf); i++)
        {  
                if (in_buf[i] == in_cFrom) set(in_buf, i, in_cTo)
        }
        //print "in_buf[i] = " in_buf[i] strNewLine
} // fReplaceNewLine()
 

void RestoreTheModule(string strSource, string strDest)
{
        string message = restoreModule(strSource, strDest)
       /* if (!null message) 
        {
                ack message
                //halt
        }*/ 
        print "Module " strDest " " message strNewLine
}  // RestoreTheModule()

void PrintFilesInDirectory()
{
        string file 
        int nLength
        int nStart
        string strSource
        string strDest
        string strNoExtension
        string strDMA = ".dma"
 
        for file in directory strSourceFolderName do 
        { 
                Buffer TextBuf = create
                if (file[0:0] == ".")      // skip the "." and ".." file names.  No other name may begin with '.'
                        continue
                if (file == strSourceFolderName)     // Don't recall why, but skip a file with exact name as Directory
                {  
                        print  ">>SearchDir, file == strSourceFolderName '" file "'\n"
                        continue
                } // end if (file == strSourceFolderName) 
                
                TextBuf = file
                nLength = length(file)
                nStart = nLength-4
                print "Start " nStart " length" nLength strNewLine
                if (file[nStart:nLength] == strDMA)  //Proceed if this is a *.dma
                {
                        strSource = strSourceFolderName "\\" file
                        fReplaceUnderscore(TextBuf)
                        file = stringOf(TextBuf)
                        nStart -= 1
                        strNoExtension = file[0:nStart]
                        strDest = strDestinationFolderName "/" strNoExtension
                        RestoreTheModule(strSource, strDest)
                } // end if (bDMAExtension)
                delete(TextBuf)
        }  // end for file in directory strSourceFolderName do 
}  //PrintFilesInDirectory()
 
void Insert(DB RestoreDialog)
{
        string strFilename
        // trace according to a folder of configuration files
        //string strSourceDirectory = get dbeSourceFolder 
        string strSourceDirectory =  strSourceFolderName
        string strDestDirectory = strDestinationFolderName
 
        pragma runLim, 0                                           //disables the "Execution Timeout" dialog
        print description (current Folder) strNewLine
        
        PrintFilesInDirectory
        infoBox "Modules Restored from " strSourceDirectory " to " strDestDirectory
        if (showing RestoreDialog)
        {
                hide(RestoreDialog)
                destroy(RestoreDialog)  // free up resources now
        } // end if (showing RestoreTheModuleBox)
} // Insert
apply(RestoreDialog, "OK", Insert)
set(dbeDefaultFolderPath, strDefaultFolderPath) // Update into the folder path area in dialog
show RestoreDialog  // No text can appear after here as it will not be executed!!!!!!!!!

Re: How to integrate Client folders with DOORS folders question
llandale - Fri Apr 27 12:18:39 EDT 2012

Gedinfo - Thu Apr 26 15:31:39 EDT 2012

In my updated code, I get a message that the "New module name is invalid".

My code appears below:
 

/*
 Rev 1.000 - This script will perform an archive restore on modules residing in the DOORS Development server area.
 Input - N/A
 Output - N/A
*/
string strModuleName
string strNewLine = "\n"
//Draws a bitmap - for canvases that displays an image
void repaint(DBE graph) {
    background(graph,
        logicalMediumIndicatorColor)
    // draw picture here
} // repaint 
 
string strDestinationFolderName = "/Test Area/ICAR/TOOLS Test Area/Test"// Doors directory
string strSourceFolderName = "U:\\DXL\\DMA"     // Laptop
string strDialogTitle = "Restore Modules "
string strDefaultFolderPath = fullName current Folder
DB RestoreDialog = create(strDialogTitle)
imageCanvas = canvas(RestoreDialog, 400, 95, repaint)               //puts the GE logo at top
DBE dbeLabel = label(RestoreDialog, "User shall be able to run a script on a directory to Restore module(s).")
DBE dbeDefaultFolderPath = field(RestoreDialog, "Folder Path:","", 80,true)   //Setting to true grays out this field

/******************************************************************************
  fReplaceUnderscore
  
  Replaces underscores in a buffer with spaces
******************************************************************************/
void fReplaceUnderscore(Buffer in_buf)
{       // Replace all occurances of underscore to space in the Buffer
        char in_cFrom = '_'
        char in_cTo = ' '
        if (null in_buf) return
        int i
        for (i=0; i<length(in_buf); i++)
        {  
                if (in_buf[i] == in_cFrom) set(in_buf, i, in_cTo)
        }
        //print "in_buf[i] = " in_buf[i] strNewLine
} // fReplaceNewLine()
 

void RestoreTheModule(string strSource, string strDest)
{
        string message = restoreModule(strSource, strDest)
       /* if (!null message) 
        {
                ack message
                //halt
        }*/ 
        print "Module " strDest " " message strNewLine
}  // RestoreTheModule()

void PrintFilesInDirectory()
{
        string file 
        int nLength
        int nStart
        string strSource
        string strDest
        string strNoExtension
        string strDMA = ".dma"
 
        for file in directory strSourceFolderName do 
        { 
                Buffer TextBuf = create
                if (file[0:0] == ".")      // skip the "." and ".." file names.  No other name may begin with '.'
                        continue
                if (file == strSourceFolderName)     // Don't recall why, but skip a file with exact name as Directory
                {  
                        print  ">>SearchDir, file == strSourceFolderName '" file "'\n"
                        continue
                } // end if (file == strSourceFolderName) 
                
                TextBuf = file
                nLength = length(file)
                nStart = nLength-4
                print "Start " nStart " length" nLength strNewLine
                if (file[nStart:nLength] == strDMA)  //Proceed if this is a *.dma
                {
                        strSource = strSourceFolderName "\\" file
                        fReplaceUnderscore(TextBuf)
                        file = stringOf(TextBuf)
                        nStart -= 1
                        strNoExtension = file[0:nStart]
                        strDest = strDestinationFolderName "/" strNoExtension
                        RestoreTheModule(strSource, strDest)
                } // end if (bDMAExtension)
                delete(TextBuf)
        }  // end for file in directory strSourceFolderName do 
}  //PrintFilesInDirectory()
 
void Insert(DB RestoreDialog)
{
        string strFilename
        // trace according to a folder of configuration files
        //string strSourceDirectory = get dbeSourceFolder 
        string strSourceDirectory =  strSourceFolderName
        string strDestDirectory = strDestinationFolderName
 
        pragma runLim, 0                                           //disables the "Execution Timeout" dialog
        print description (current Folder) strNewLine
        
        PrintFilesInDirectory
        infoBox "Modules Restored from " strSourceDirectory " to " strDestDirectory
        if (showing RestoreDialog)
        {
                hide(RestoreDialog)
                destroy(RestoreDialog)  // free up resources now
        } // end if (showing RestoreTheModuleBox)
} // Insert
apply(RestoreDialog, "OK", Insert)
set(dbeDefaultFolderPath, strDefaultFolderPath) // Update into the folder path area in dialog
show RestoreDialog  // No text can appear after here as it will not be executed!!!!!!!!!

I'm pretty sure it will restore only in the "current Folder".
  • Folder fld = folder(strDestinationFolderName)
  • current = fld
The ModuleName parameter is optional way to rename the module; otherwise it uses the name it finds in the archive; and in any case must be an un-qualified name (no slashes, e.g. "ModName").

On other news...
  • move "Buffer TextBuf = create" up before the loop
  • move delete TextBuf down after the loop
  • Doesn't matter here since you are requesting a byte beyond the name, but the following is technically correct:
    • if (file[nStart:nLength-1] == strDMA) //Proceed if this is a *.dma
  • You should do some testing vis-a-vis this line; presumbly creating a file named "DMA" in the \DMA folder.
    • if (file == strSourceFolderName) // Don't recall why, but skip a file with exact name as Directory

-Louie